<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>友洗环保</title>
    <link rel="stylesheet" type="text/css" href="./css/ali-icon/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.2.0.css" />
    <style>
        [v-cloak] {
            display: none;
        }

        .disnone {
            display: none;
        }

        .disblock {
            display: block;
        }
    </style>
</head>

<body>
    <div id="app">
        <header class="aui-bar aui-bar-nav disnone" style="padding-top:25px; background-color:#00caa1;" :data-id="index" v-for="(vo,index) in menuLlist" v-bind:class="{'disblock': cou_index== index}">
            {{vo.title}}
        </header>
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item" tapmode v-for="(vo,index) in menuLlist" v-bind:class="{'aui-active': cou_index == index}" @click="change_menu(index)">
                <img :src="vo.icon" v-show="cou_index != index" />
                <img :src="vo.a_icon" v-show="cou_index == index" />
                <div class="aui-bar-tab-label">{{vo.title}}</div>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/base64.js"></script>
<script type="text/javascript" src="./script/md5.js"></script>
<script type="text/javascript" src="./script/common/api.js"></script>
<script type="text/javascript" src="./script/common/vue.js"></script>
<script>
    var base64 = new Base64();
    var jpush = null; // 极光推送
    var baiduLocation = null; // 百度定位
    apiready = function() {
        jpush = api.require('ajpush');
        baiduLocation = api.require('baiduLocation');
        // 获取极光regid
        jpush.getRegistrationId(function(ret, err){
            api.setGlobalData({
                key: 'rRegistrationId',
                value: ret.id
            });            
        });
        var headerlist = $api.domAll('header');
        for (var i = 0; i < headerlist.length; i++) {
            $api.fixIos7Bar(headerlist[i]); //修复ios系统bar
        }
        $api.auth(function(ret, err) {}); //获取token
        vm.init();
    };
    setInterval("vm.getAddress()", 60000); //每隔一分钟上传一次坐标
    var vm = new Vue({
        el: '#app',
        data: {
            cou_index: 0, //显示当前索引
            menuLlist: [{
                title: '我的订单',
                icon: './image/bar/order.png',
                a_icon: './image/bar/a_order.png'
            }, {
                title: '我的收入',
                icon: './image/bar/income.png',
                a_icon: './image/bar/a_income.png'
            }, {
                title: '个人中心',
                icon: './image/bar/my.png',
                a_icon: './image/bar/a_my.png'
            }],
            orderStatus: {
                PENDING: 0,
                CHECK_PENDING: 1,
                UNACCEPTED: 2,
                ACCEPTED: 3,
                TRADE_SUCCESS: 4,
                TRADE_CLOSE: 5,
                WAIT_FOR_SERVICE: 6
            }
        },
        methods: {
            init: function() {
                var myFrames = [];
                for (var i = 0; i < vm.menuLlist.length; i++) {
                    myFrames.push({
                        name: 'frame' + i,
                        url: './html/frame' + i + '.html',
                        bgColor: "#bgcolor",
                        bounces: true
                    })
                }

                myFrames.push({
                    name: 'frame3',
                    url: './html/frame3.html',
                    bgColor: "#bgcolor",
                    bounces: true
                });

                myFrames.push({
                    name: 'frame4',
                    url: './html/frame4.html',
                    bgColor: "#bgcolor",
                    bounces: true
                });

                myFrames.push({
                    name: 'frame5',
                    url: './html/frame5.html',
                    bgColor: "#bgcolor",
                    bounces: true
                });

                api.openFrameGroup({
                    name: 'IndexGroup', //app首页frame组预加载
                    background: 'bgcolor',
                    scrollEnabled: true,
                    preload : 0,
                    rect: {
                        x: 0,
                        y: $api.dom('header').offsetHeight,
                        w: api.winWidth,
                        h: api.winHeight - $api.dom('header').offsetHeight - $api.dom('footer').offsetHeight
                    },
                    index: vm.cou_index,
                    frames: myFrames
                }, function(ret, err) {


                });
            },
            change_menu: function(index) {
                if (vm.cou_index == index) {
                    return false;
                }
                //切换菜单
                vm.cou_index = index;
                if (index == 0) {
                    vm.hasAcceptedOrderList(function() {
                        api.setFrameGroupIndex({
                            name: 'IndexGroup',
                            index: index,
                            reload: true
                        });
                    });
                } else {
                    api.setFrameGroupIndex({
                        name: 'IndexGroup',
                        index: index,
                        reload: true
                    });
                }
            }, // 百度定位坐标发送 bmLocation
            getAddress: function() {
                baiduLocation.startLocation({
                    accuracy: '10m',
                    filter: 1,
                    autoStop: true
                }, function(ret, err) {
                    if (ret.status) {
                        //jpush.getRegistrationId(function(ret, err){
                        //  alert('极光regid: '+ret.id);
                        //});
                        var isorder = api.getGlobalData({
                            key: 'isorder'
                        });
                        var curOrder = api.getGlobalData({
                            key: 'curOrder'
                        });
                        var params = {}
                        params.technician = api.getGlobalData({
                            key: 'technicianid'
                        });
                        params.lng = ret.longitude;
                        params.lat = ret.latitude; //orderId
                        if (isorder) {
                            params.order = curOrder.id
                        } else {
                            params.order = ''
                        }
                        if (params.technician != '') {
                            $api.ajax(function(ret, err) {
                                //  console.log('retbaidu: ' + JSON.stringify(ret));
                            }, 'v1/technicianCoordinate/', 'post', params);
                        }
                    } else {
                        alert(JSON.stringify(err));
                    }
                });
            },
            hasAcceptedOrderList: function(callback) {
                var params = {}
                params.technician = api.getGlobalData({
                    key: 'technicianid'
                });
                params.status = this.orderStatus.ACCEPTED + ',' + this.orderStatus.WAIT_FOR_SERVICE;
                params.asc = true;
                $api.ajax(function(ret, err) {
                    if (ret.length > 0) {
                        alert('您还有进行中的订单，请先处理进行中的订单。');
                        api.setFrameGroupIndex({
                            name: 'IndexGroup',
                            index: 3,
                            reload: true
                        });
                    } else {
                        callback();
                    }
                }, 'order/findOrderList', 'post', params);
            }
        }
    });
</script>

</html>
